<template>
  <div>
    <div :class="isActive ? 'active' : 'inActive'"
         :id="disabled ? 'notAllowed' : 'inActive'"
         @click="switchChange"
         class="switchVue">
      <span :class="isActive ? 'active-text' : 'inActive-text'"
            class="switchText">{{isActive ? activeWord : offWord}}</span>
      <span :class="isActive ? 'active-btn' : 'inActive-btn'"
            class="switchBtn"></span>
    </div>
  </div>
</template>
<script>
export default {
  name: 'switchVue',
  props: {
    isActive: {
      type: Boolean,
      default: true
    },
    activeWord: {
      type: String,
      default: '是'
    },
    offWord: {
      type: String,
      default: '否'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    switchChange () {
      this.$emit('switchChange')
    }
  }
}
</script>

<style lang="less" scoped>
.switchVue {
  cursor: pointer;
  width: 55px;
  height: 20px;
  border-radius: 10px;
  position: relative;
}
#notAllowed {
  cursor: not-allowed !important;
}
.active-text {
  left: 8px;
}
.inActive-text {
  right: 8px;
}
.inActive-btn {
  left: 1px;
}
.active-btn {
  right: 1px;
}
.switchText {
  position: absolute;
  // top: 5px;
  font-size: 12px;
  color: #fff;
}
.switchBtn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  display: inline-block;
  position: absolute;
  top: 1px;
}
.inActive {
  background: #c7c7c7;
}
.active {
  background: #1990ff;
}
</style>
